﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using BRMC.IntelligentCommunity.Dto;
using BRMC.IntelligentCommunity.IntelligentCommunity.Parkings;
using BRMC.IntelligentCommunity.IntelligentCommunity.Sys;
using BRMC.IntelligentCommunity.Localization;
using BRMC.IntelligentCommunity.Parkings.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BRMC.IntelligentCommunity.Parkings
{
  public  class ParkingAppService : AsyncCrudAppService<
          Parking,
          ParkingDto,
          long,
           PagedAndSortedInputDto,
          CreateParkingDto,
          UpdateParkingDto
          >

 
    {
        private readonly IRepository<Sys_neighbourhood_info, int> _neighbourhood_info;
        private readonly IRepository<Parking, long> _repository;
        //private readonly IRepository<user_base_info_view, long> _repository;
        public ParkingAppService(IRepository<Parking, long> repository, IRepository<Sys_neighbourhood_info, int> neighbourhood_info) :base(repository)
        {
            _neighbourhood_info = neighbourhood_info;
            _repository = repository;
        }


        public async Task<ListResultDto<ComboboxItemDto>> GetComboxSupplier()
        {
         
            var query = _neighbourhood_info.GetAll().Where(c=>c.TenantId == AbpSession.TenantId).Select(e => new ComboboxItemDto(e.Id.ToString(), e.Name)).ToList();
            return new ListResultDto<ComboboxItemDto>(query);
        }

        public async Task<GetParkingForEdtiOutput> GetParkingForEdit(NullableIdDto input)
        {
            Parking parking = null;
            if (input.Id.HasValue)
            {
                parking = await _repository.FirstOrDefaultAsync(c => c.Id == input.Id);
            }

            var output = new GetParkingForEdtiOutput();

            output.ParkingEdit = parking != null      ? ObjectMapper.Map<ParkingEditDto>(parking)    : new ParkingEditDto();

            

                    output.Neighbourhoods = _neighbourhood_info.GetAll().Where(c => c.TenantId == AbpSession.TenantId)
                .Select(e => new ComboboxItemDto(e.Id.ToString(), e.Name)).ToList();

            return output;
        }
    }
}
